package org.springblade.modules.platform.algorithm.method;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ht.utils.AbsoluteDeflection;
import com.ht.utils.CalModel;
import com.ht.utils.RelativeDeflection;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.platform.dto.DeviceRuningStateDTO;
import org.springblade.modules.platform.dto.PlumbDeviceStateDTO;
import org.springblade.modules.platform.entity.*;
import org.springblade.modules.platform.service.*;
import org.springblade.modules.platform.vo.*;
import org.springblade.modules.platform.vo.enums.BenchTypeNameEnum;
import org.springblade.modules.platform.vo.enums.DataStrategyEnum;
import org.springblade.modules.platform.vo.enums.PhysicalQuantityEnum;
import org.springblade.modules.platform.vo.enums.ProductTypeEnum;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Component
@AllArgsConstructor
@Slf4j
public class BaseStationMethod4 {
	private final IMeasuringChainPlatformTypeService iMeasuringChainPlatformTypeService;
	private final IMeasuringChainPlatformInfoService iMeasuringChainPlatformInfoService;
	private final IMeasuringPlatformTypeService iMeasuringPlatformTypeService;
	private final IDeviceTableService iDeviceTableService;
	private final IAbsolutelyValueTableService iAbsolutelyValueTableService;
	private final ISysParameterService iSysParameterService;
	private final IMeasuringChainTableService iMeasuringChainTableService;
	public static final Map<String,Double> map_9 = new HashMap<String,Double>();
	public static final Map<String,Double> map_1 = new HashMap<String,Double>();
	public static final Map<String,Double> map_18 = new HashMap<String,Double>();
	private final IVerticalCoordinateTableService iVerticalCoordinateTableService;
	private final BladeRedis bladeRedis;
	/**
	 * 2号和17号倾角为0
	 * @param deviceRuningStateDTO
	 * @param gatherEvent
	 */
	public Double installDeviceRuningState(DeviceRuningStateDTO deviceRuningStateDTO, Integer gatherEvent, Integer arcsecondType, Double arcsecondValue,Integer measurChainDirection) {

		try {
			double x9 = 0.0;
			double y9 = 0.0;

			AbsolutelyValueTable one1 = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
				.eq(AbsolutelyValueTable::getMeasurChainDirection, measurChainDirection).eq(AbsolutelyValueTable::getBenchTypeCode, 2526));//正
			DeviceRuningStateDTO.DeviceListDTO deviceListDTO3 = deviceRuningStateDTO.getDeviceList().stream().filter(l -> l.getDeviceId().equals("26")).findFirst().orElse(null);
			DeviceRuningStateDTO.DeviceListDTO deviceListDTO4 = deviceRuningStateDTO.getDeviceList().stream().filter(l -> l.getDeviceId().equals("25")).findFirst().orElse(null);
			double x26 = Double.parseDouble(deviceListDTO3.getAttributeListDTO().get(0).getValue().toString());
			double y25 = Double.parseDouble(deviceListDTO4.getAttributeListDTO().get(0).getValue().toString());

			VerticalCoordinateTable verticalCoordinateTable = new VerticalCoordinateTable();
			verticalCoordinateTable.setX(x26);
			verticalCoordinateTable.setY(y25);
			verticalCoordinateTable.setDeptName("2526");
			verticalCoordinateTable.setDeptId(1701072301627441154L);
			verticalCoordinateTable.setGatherTime(deviceRuningStateDTO.getAcquisitionTime());
			iVerticalCoordinateTableService.save(verticalCoordinateTable);

			if(one1==null){
				one1 = new AbsolutelyValueTable();
				one1.setBenchTypeCode(2526);
				one1.setY(y25);
				one1.setDipX(x26);
				one1.setMeasurChainDirection(measurChainDirection);
				iAbsolutelyValueTableService.save(one1);
			}
			x9 = x9 + (((x26 - one1.getDipX()) / 100 )  * -1);
			y9 = y9 + ((y25 - one1.getY()) / 100 );


			AbsolutelyValueTable nOne = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
				.eq(AbsolutelyValueTable::getMeasurChainDirection, measurChainDirection).eq(AbsolutelyValueTable::getBenchTypeCode, 2728));//dao
			DeviceRuningStateDTO.DeviceListDTO deviceListDTO27 = deviceRuningStateDTO.getDeviceList().stream().filter(l -> l.getDeviceId().equals("28")).findFirst().orElse(null);
			DeviceRuningStateDTO.DeviceListDTO deviceListDTO28 = deviceRuningStateDTO.getDeviceList().stream().filter(l -> l.getDeviceId().equals("27")).findFirst().orElse(null);
			double x2728 = Double.parseDouble(deviceListDTO27.getAttributeListDTO().get(0).getValue().toString());
			double y2728 = Double.parseDouble(deviceListDTO28.getAttributeListDTO().get(0).getValue().toString());
			VerticalCoordinateTable verticalCoordinateTable1 = new VerticalCoordinateTable();
			verticalCoordinateTable1.setX(x2728);
			verticalCoordinateTable1.setY(y2728);
			verticalCoordinateTable1.setDeptName("2728");
			verticalCoordinateTable1.setDeptId(1701072301627441154L);
			verticalCoordinateTable1.setGatherTime(deviceRuningStateDTO.getAcquisitionTime());
			iVerticalCoordinateTableService.save(verticalCoordinateTable1);

			if(nOne==null){
				nOne = new AbsolutelyValueTable();
				nOne.setBenchTypeCode(2728);
				nOne.setY(y2728);
				nOne.setDipX(x2728);
				nOne.setMeasurChainDirection(measurChainDirection);
				iAbsolutelyValueTableService.save(nOne);
			}
			x9 = x9 + (((x2728 - nOne.getDipX()) / 100 )* -1);
			y9 = y9 + (((y2728 - nOne.getY()) / 100 )* -1);


			AbsolutelyValueTable nOne29 = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
				.eq(AbsolutelyValueTable::getMeasurChainDirection, measurChainDirection).eq(AbsolutelyValueTable::getBenchTypeCode, 2930));//dao
			DeviceRuningStateDTO.DeviceListDTO deviceListDTO29 = deviceRuningStateDTO.getDeviceList().stream().filter(l -> l.getDeviceId().equals("29")).findFirst().orElse(null);
			DeviceRuningStateDTO.DeviceListDTO deviceListDTO30 = deviceRuningStateDTO.getDeviceList().stream().filter(l -> l.getDeviceId().equals("30")).findFirst().orElse(null);
			double x29 = Double.parseDouble(deviceListDTO29.getAttributeListDTO().get(0).getValue().toString());
			double y30 = Double.parseDouble(deviceListDTO30.getAttributeListDTO().get(0).getValue().toString());

			VerticalCoordinateTable verticalCoordinateTable2 = new VerticalCoordinateTable();
			verticalCoordinateTable2.setX(x29);
			verticalCoordinateTable2.setY(y30);
			verticalCoordinateTable2.setDeptName("2930");
			verticalCoordinateTable2.setDeptId(1701072301627441154L);
			verticalCoordinateTable2.setGatherTime(deviceRuningStateDTO.getAcquisitionTime());
			iVerticalCoordinateTableService.save(verticalCoordinateTable2);

			if(nOne29==null){
				nOne29 = new AbsolutelyValueTable();
				nOne29.setBenchTypeCode(2930);
				nOne29.setY(y30);
				nOne29.setDipX(x29);
				nOne29.setMeasurChainDirection(measurChainDirection);
				iAbsolutelyValueTableService.save(nOne29);
			}
			x9 = x9 + (((x29 - nOne29.getDipX()) / 100 ) * -1);
			y9 = y9 + (((y30 - nOne29.getY()) / 100 )* -1);


			AbsolutelyValueTable nOne3132 = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
				.eq(AbsolutelyValueTable::getMeasurChainDirection, measurChainDirection).eq(AbsolutelyValueTable::getBenchTypeCode, 3132));//dao
			DeviceRuningStateDTO.DeviceListDTO deviceListDTO32 = deviceRuningStateDTO.getDeviceList().stream().filter(l -> l.getDeviceId().equals("32")).findFirst().orElse(null);
			DeviceRuningStateDTO.DeviceListDTO deviceListDTO31 = deviceRuningStateDTO.getDeviceList().stream().filter(l -> l.getDeviceId().equals("31")).findFirst().orElse(null);
			double x32 = Double.parseDouble(deviceListDTO32.getAttributeListDTO().get(0).getValue().toString());
			double y31 = Double.parseDouble(deviceListDTO31.getAttributeListDTO().get(0).getValue().toString());

			VerticalCoordinateTable verticalCoordinateTable3 = new VerticalCoordinateTable();
			verticalCoordinateTable3.setX(x32);
			verticalCoordinateTable3.setY(y31);
			verticalCoordinateTable3.setDeptName("3132");
			verticalCoordinateTable3.setDeptId(1701072301627441154L);
			verticalCoordinateTable3.setGatherTime(deviceRuningStateDTO.getAcquisitionTime());
			iVerticalCoordinateTableService.save(verticalCoordinateTable3);

			if(nOne3132==null){
				nOne3132 = new AbsolutelyValueTable();
				nOne3132.setBenchTypeCode(3132);
				nOne3132.setY(y31);
				nOne3132.setDipX(x32);
				nOne3132.setMeasurChainDirection(measurChainDirection);
				iAbsolutelyValueTableService.save(nOne3132);
			}
			x9 = x9 + (((x32 - nOne3132.getDipX()) / 100 ) * -1);
			y9 = y9 + ((y31 - nOne3132.getY()) / 100 );


			AbsolutelyValueTable nOne3334 = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
				.eq(AbsolutelyValueTable::getMeasurChainDirection, measurChainDirection).eq(AbsolutelyValueTable::getBenchTypeCode, 3334));//dao
			DeviceRuningStateDTO.DeviceListDTO deviceListDTO33 = deviceRuningStateDTO.getDeviceList().stream().filter(l -> l.getDeviceId().equals("33")).findFirst().orElse(null);
			DeviceRuningStateDTO.DeviceListDTO deviceListDTO34 = deviceRuningStateDTO.getDeviceList().stream().filter(l -> l.getDeviceId().equals("34")).findFirst().orElse(null);
			double y33 = Double.parseDouble(deviceListDTO33.getAttributeListDTO().get(0).getValue().toString());
			double x34 = Double.parseDouble(deviceListDTO34.getAttributeListDTO().get(0).getValue().toString());

			VerticalCoordinateTable verticalCoordinateTable4 = new VerticalCoordinateTable();
			verticalCoordinateTable4.setX(x34);
			verticalCoordinateTable4.setY(y33);
			verticalCoordinateTable4.setDeptName("3334");
			verticalCoordinateTable4.setDeptId(1701072301627441154L);
			verticalCoordinateTable4.setGatherTime(deviceRuningStateDTO.getAcquisitionTime());
			iVerticalCoordinateTableService.save(verticalCoordinateTable4);

			if(nOne3334==null){
				nOne3334 = new AbsolutelyValueTable();
				nOne3334.setBenchTypeCode(3334);
				nOne3334.setY(y33);
				nOne3334.setDipX(x34);
				nOne3334.setMeasurChainDirection(measurChainDirection);
				iAbsolutelyValueTableService.save(nOne3334);
			}
			y9 = y9 + ((y33 - nOne3334.getY()) / 100 );
			x9 = x9 + (((x34 - nOne3334.getDipX()) / 100 ) * -1);

			map_9.put("x",x9);
			map_9.put("y",y9);

			Long acquisitionTime = deviceRuningStateDTO.getAcquisitionTime();//采集时间
			Long deptMeasuringInfoId = deviceRuningStateDTO.getDeptMeasuringInfoId();//测量链编号
			BigDecimal rietschlePressure = deviceRuningStateDTO.getRietschlePressure();//真空泵气压值
			List<DeviceRuningStateDTO.DeviceListDTO> deviceList = deviceRuningStateDTO.getDeviceList();//设备集合
			String acquisitionFlag = deviceRuningStateDTO.getAcquisitionFlag();
			String connectionId = deviceRuningStateDTO.getConnectionId();
			MeasuringChainTable byId = iMeasuringChainTableService.getById(deptMeasuringInfoId);

			List<MeasuringChainPlatformType> measuringChainPlatformTypeList = iMeasuringChainPlatformTypeService.getMeasuringChainPlatformTypeList(deptMeasuringInfoId);
			if(Func.isEmpty(measuringChainPlatformTypeList)){
				return null;
			}

			BigDecimal i = new BigDecimal(65).divide(new BigDecimal(22),2, RoundingMode.HALF_UP);
			BigDecimal s = new BigDecimal(30);
			List<MeasuringChainDetailsVO> measuringChainDetailsVOS = new ArrayList<>();
			for (MeasuringChainPlatformType x : measuringChainPlatformTypeList) {
				if(Objects.equals(x.getMeasuringTypeCode(), measurChainDirection)){
					MeasuringChainDetailsVO measuringChainDetailsVO = getMeasuringPlatform(x.getId(),
						deviceList,
						x.getMeasuringTypeCode(),
						acquisitionTime,
						s,connectionId,
						acquisitionFlag,i,
						deptMeasuringInfoId,arcsecondValue);
					if(measuringChainDetailsVO!=null){
						measuringChainDetailsVO.setGatherTime(acquisitionTime);
						measuringChainDetailsVO.setMeasurChainDirection(x.getMeasuringTypeCode());
						measuringChainDetailsVO.setRietschlePressure(rietschlePressure);
						measuringChainDetailsVO.setGatherEvent(gatherEvent);
						measuringChainDetailsVO.setMeasurChain(byId.getChainName());
						measuringChainDetailsVO.setMeasurChainCode(deptMeasuringInfoId);
						measuringChainDetailsVOS.add(measuringChainDetailsVO);

					}

					s = measuringChainDetailsVO.getI();
				}


			}
			return saveMeasuringChainDetails(measuringChainDetailsVOS, acquisitionFlag, arcsecondType, arcsecondValue,measurChainDirection);
		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;


	}

	/**
	 * 计算测量连，所有侧台的工程量，物理量
	 * @param measuringTypeId
	 * @param deviceList
	 * @return
	 */
	private MeasuringChainDetailsVO getMeasuringPlatform(Long measuringTypeId,
														 List<DeviceRuningStateDTO.DeviceListDTO> deviceList,
														 Integer measuringTypeCode,
														 Long acquisitionTime,
														 BigDecimal s,
														 String connectionId,
														 String acquisitionFlag,  BigDecimal i,Long deptMeasuringInfoId ,double arcsecondValue){
		try {
			MeasuringChainDetailsVO measuringChainDetailsVO = new MeasuringChainDetailsVO();
			//排序以后所有配置的侧台
			List<MeasuringChainPlatformInfo> measuringChainPlatformInfo = iMeasuringChainPlatformInfoService.getMeasuringChainPlatformInfo(measuringTypeId);
			if(measuringChainPlatformInfo==null){
				return null;
			}
			List<MeasuringPlatformVO> list = new ArrayList<>();
			for (MeasuringChainPlatformInfo chainPlatformInfo : measuringChainPlatformInfo) {
				Long measuringPlatformId = chainPlatformInfo.getMeasuringPlatformId();//侧台编号
				MeasuringPlatformTypeVO measuringPlatformTypeVO = iMeasuringPlatformTypeService.deileMeasuringPlatformType(measuringPlatformId,  measuringTypeCode);//侧台所有计算策略
				Double yAxis = null;
				Long parentPlatformId = chainPlatformInfo.getParentPlatformId();
				if(parentPlatformId!=null){
					MeasuringChainPlatformInfo platformInfo = measuringChainPlatformInfo.stream().filter(x -> x.getMeasuringPlatformId().equals(parentPlatformId)).findFirst().get();
					yAxis = platformInfo.getyAxis();

				}
				MeasuringPlatformVO measuringPlatformVO = measuringPlatformCount(measuringPlatformTypeVO,
					deviceList,measuringTypeCode,
					chainPlatformInfo,list,acquisitionTime,s,connectionId,acquisitionFlag,deptMeasuringInfoId,arcsecondValue,yAxis);
				assert measuringPlatformVO != null;
				measuringPlatformVO.setMeasuringPlatformId(chainPlatformInfo.getMeasuringPlatformId());
				measuringPlatformVO.setMeasuringPlatformName(chainPlatformInfo.getMeasuringPlatformName());
				measuringPlatformVO.setBenchTypeCode(measuringPlatformTypeVO.getMeasuringPlatformType());
				measuringPlatformVO.setBenchTypeName(Objects.requireNonNull(BenchTypeNameEnum.getEnum(measuringPlatformTypeVO.getMeasuringPlatformType())).getMsg());
				measuringPlatformVO.setSort(chainPlatformInfo.getSort());
				list.add(measuringPlatformVO);
				s = s.add(i);

			}
			measuringChainDetailsVO.setMeasuringPlatformVOS(list);
			measuringChainDetailsVO.setMeasurChainCode(measuringTypeId);
			measuringChainDetailsVO.setI(s);
			return measuringChainDetailsVO;
		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;


	}







	/**
	 * 单个侧台计算物理量，工程量
	 * @param measuringPlatformTypeVO
	 * @param deviceList
	 */
	private MeasuringPlatformVO measuringPlatformCount(MeasuringPlatformTypeVO measuringPlatformTypeVO,
													   List<DeviceRuningStateDTO.DeviceListDTO> deviceList,
													   Integer measuringTypeCode,
													   MeasuringChainPlatformInfo chainPlatformInfo,
													   List<MeasuringPlatformVO> measuringPlatformVOS,
													   Long acquisitionTime,
													   BigDecimal bi,
													   String connectionId,
													   String acquisitionFlag,
													   Long deptMeasuringInfoId
		,double arcsecondValue,Double yAxis){
		try {
			MeasuringPlatformConfigVO measuringPlatformConfigVO = null;
			List<MeasuringPlatformConfigVO> list1 = measuringPlatformTypeVO.getList();//如果没配置计算策略默认走计算
			if(!Func.isEmpty(list1)){
				measuringPlatformConfigVO = list1.get(0);
			}
			String measuringPlatformName = chainPlatformInfo.getMeasuringPlatformName();

			switch (Objects.requireNonNull(BenchTypeNameEnum.getEnum(measuringPlatformTypeVO.getMeasuringPlatformType()))){
				case BASICS://基点测台

					Map<String,DeviceTableVO> mapd = new HashMap<>();
					List<String> list2 = Arrays.asList(measuringPlatformTypeVO.getDeviceId().split(","));
					list2.forEach(x->{
						DeviceTableVO deviceTableVO = iDeviceTableService.selectDeviceById(x);
						mapd.put(deviceTableVO.getDeviceChannelId(),deviceTableVO);
						String deviceChannelId = deviceTableVO.getDeviceChannelId();
						Optional<DeviceRuningStateDTO.DeviceListDTO> first = deviceList.stream().filter(l -> l.getDeviceId().equals(deviceChannelId)).findFirst();
						if(first.isPresent()){
							DeviceRuningStateDTO.DeviceListDTO deviceListDTO = first.get();//设备上报的本侧台的原始数据

						}

					});
					List<String> list = Arrays.asList(measuringPlatformTypeVO.getDeviceChannelId().split(","));

					AbsoluteValueVO absoluteValue = getAbsoluteValue(list,mapd, measuringPlatformConfigVO, deviceList,measuringPlatformTypeVO.getId(),acquisitionTime);//工程量


					List<String> stringList = absoluteValue.getStringList();
					if(!Func.isEmpty(stringList)){
						List<String> collect1 = stringList.stream().distinct().collect(Collectors.toList());
						collect1.forEach(c->{
							DeviceTableVO deviceTableVO = iDeviceTableService.selectDeviceById(c);
							String deviceChannelId = deviceTableVO.getDeviceChannelId();
							Optional<DeviceRuningStateDTO.DeviceListDTO> first = deviceList.stream().filter(l -> l.getDeviceId().equals(deviceChannelId)).findFirst();
							if(first.isPresent()){
								DeviceRuningStateDTO.DeviceListDTO deviceListDTO = first.get();//设备上报的本侧台的原始数据

							}
						});
					}
					/* onceValue1.addAll(onceValue5);*/
					return  MeasuringPlatformVO.builder().physicalQuantityVO(null).absoluteValueVO(absoluteValue).build();
				case ORDINARY://普通测台
					String deviceChannelId = measuringPlatformTypeVO.getDeviceChannelId();
					String deviceId = measuringPlatformTypeVO.getDeviceId();
					DeviceRuningStateDTO.DeviceListDTO deviceListDTO = null;
					Optional<DeviceRuningStateDTO.DeviceListDTO> first = deviceList.stream().filter(l -> l.getDeviceId().equals(deviceChannelId)).findFirst();
					if(first.isPresent()){
						deviceListDTO = first.get();//设备上报的本侧台的原始数据
					}else {
						//查询默认值
					}

					Long parentPlatformId = chainPlatformInfo.getParentPlatformId();//付侧台

					log.info("计算物理量开始:{}",measuringPlatformTypeVO.getMeasuringPlatformName());
					AbsoluteValueVO ordinaryAbsoluteValue;
					PhysicalQuantityVO physicalQuantity = getPhysicalQuantity(deviceListDTO, parentPlatformId, measuringTypeCode,deviceList,measuringPlatformTypeVO.getId(), deviceId, deptMeasuringInfoId);//物理量
					if(parentPlatformId!=null){
						MeasuringPlatformVO parentPlatformVO = measuringPlatformVOS.stream().filter(l -> l.getMeasuringPlatformId().equals(chainPlatformInfo.getParentPlatformId())).findFirst().get();//付侧台工程量和物理量

						if(measuringPlatformConfigVO==null){
							ordinaryAbsoluteValue = getOrdinaryAbsoluteValue(measuringPlatformTypeVO.getId(),measuringPlatformConfigVO, null, parentPlatformVO, chainPlatformInfo,physicalQuantity,measuringTypeCode,yAxis);//工程量
						}else {
							ordinaryAbsoluteValue = getOrdinaryAbsoluteValue(measuringPlatformTypeVO.getId(),measuringPlatformConfigVO, deviceList, parentPlatformVO, chainPlatformInfo, physicalQuantity,measuringTypeCode,yAxis);//工程量
						}
					}else {
						//需要知道高精度传感器的值
						ordinaryAbsoluteValue = getOrdinaryAbsoluteValue2(measuringPlatformConfigVO, deviceList,measuringTypeCode, arcsecondValue,acquisitionTime);//高精度传感器带入
						physicalQuantity.setDipX(ordinaryAbsoluteValue.getAlpha());
						physicalQuantity.setDipY(ordinaryAbsoluteValue.getBeta());
					}
					List<String> stringList1 = ordinaryAbsoluteValue.getStringList();
					if(!Func.isEmpty(stringList1)){
						List<String> collect1 = stringList1.stream().distinct().collect(Collectors.toList());
						collect1.forEach(c->{
							DeviceTableVO deviceTableVO = iDeviceTableService.selectDeviceById(c);
							Optional<DeviceRuningStateDTO.DeviceListDTO> first1 = deviceList.stream().filter(l -> l.getDeviceId().equals(deviceTableVO.getDeviceChannelId())).findFirst();
							if(first1.isPresent()){
								DeviceRuningStateDTO.DeviceListDTO deviceListDTO1 = first1.get();//设备上报的本侧台的原始数据

							}
						});
					}

					log.info("侧台名称:{}",measuringPlatformTypeVO.getMeasuringPlatformName());
					log.info("物理量:{}",physicalQuantity);
					log.info("工程量:{}",ordinaryAbsoluteValue);
					/*   onceValue.addAll(onceValue5);*/
					return  MeasuringPlatformVO.builder().physicalQuantityVO(physicalQuantity).absoluteValueVO(ordinaryAbsoluteValue).build();
			}
		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;

	}
	/**
	 *普通侧台工程量
	 * @param measuringPlatformConfigVO(测量连方向)
	 * @param deviceList（父侧台工程量）
	 * @return
	 */
	private AbsoluteValueVO getOrdinaryAbsoluteValue2(MeasuringPlatformConfigVO measuringPlatformConfigVO,
													  List<DeviceRuningStateDTO.DeviceListDTO> deviceList,
													  Integer measuringTypeCode,
													  Double arcsecondValue,
													  Long gatherTime){//1正向 2逆向
		try {
			Double alpha = 0.0;
			Double beta = 0.0;
			Double gama = 0.0;
			Double x = 0.0;
			Double y = 0.0;
			Double z = 0.0;

			List<String> strings = new ArrayList<>();
			if(measuringPlatformConfigVO!=null){//走配置的策略

				Integer xType = measuringPlatformConfigVO.getxType();
				if(xType!=null){
					if(xType.equals(DataStrategyEnum.MANUAL.getCode())){
						x = Double.parseDouble(measuringPlatformConfigVO.getxValue());
					}else {
						//未给出结算规则
					}
				}
				Integer yType = measuringPlatformConfigVO.getyType();
				if(yType!=null){
					if(yType.equals(DataStrategyEnum.MANUAL.getCode())){
						y = Double.parseDouble(measuringPlatformConfigVO.getyValue());
					}else {
						//未给出结算规则
					}
				}
				Integer zType = measuringPlatformConfigVO.getzType();
				if(zType!=null){
					if(zType.equals(DataStrategyEnum.MANUAL.getCode())){
						z = Double.parseDouble(measuringPlatformConfigVO.getzValue());
					}else {
						//未给出结算规则
					}
				}
				Map<String, Double> dataStrategy = null;
				Integer alphaType = measuringPlatformConfigVO.getAlphaType();
				if(alphaType!=null){
					if(alphaType.equals(DataStrategyEnum.MANUAL.getCode())){
						alpha = Double.parseDouble(measuringPlatformConfigVO.getAlphaValue());
					}else if(alphaType.equals(DataStrategyEnum.COMPANY.getCode())){
						dataStrategy =  getDataStrategy(measuringPlatformConfigVO.getMeasuringPlatformId(),measuringPlatformConfigVO.getAlphaValue(),measuringPlatformConfigVO.getPlatformTypeCode(),deviceList);//ccd1AfterDipx1
						alpha = dataStrategy.get("dipX");

						strings.add(measuringPlatformConfigVO.getAlphaValue());
					}
				}
				Integer betaType = measuringPlatformConfigVO.getBetaType();
				if(betaType!=null){
					if(betaType.equals(DataStrategyEnum.MANUAL.getCode())){
						beta = Double.parseDouble(measuringPlatformConfigVO.getBetaValue());
					}else if(betaType.equals(DataStrategyEnum.COMPANY.getCode())){
						beta = dataStrategy.get("dipY");
						strings.add(measuringPlatformConfigVO.getBetaValue());
					}
				}
				Integer gamaType = measuringPlatformConfigVO.getGamaType();
				if(gamaType!=null){
					if(gamaType.equals(DataStrategyEnum.MANUAL.getCode())){
						gama = Double.parseDouble(measuringPlatformConfigVO.getGamaValue());
					}else if(gamaType.equals(DataStrategyEnum.COMPANY.getCode())){
						//没有提供算法
					}
				}
			}

			if(arcsecondValue==null){
				gama = 0.0;
			}else {
				gama =  arcsecondValue * 4.85E-6;

			}
			log.info("第二次1号侧台的game值为:{}",gama);
			log.info("程量为:{}",AbsoluteValueVO.builder().x(x).y(y).z(z).alpha(alpha).beta(beta).gama(gama).stringList(strings).build());
			return AbsoluteValueVO.builder().x(x).y(y).z(z).alpha(alpha).beta(beta).gama(gama).stringList(strings).build();
		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;



	}


	/**
	 *普通侧台工程量
	 * @param measuringPlatformConfigVO(测量连方向)
	 * @param deviceList（父侧台工程量）
	 * @param parentPlatformVO（本侧台的工程量）
	 * @param chainPlatformInfo（本侧台的物理量）
	 * @return
	 */
	private AbsoluteValueVO getOrdinaryAbsoluteValue(Long measuringPlatformId,MeasuringPlatformConfigVO measuringPlatformConfigVO,
													 List<DeviceRuningStateDTO.DeviceListDTO> deviceList,
													 MeasuringPlatformVO parentPlatformVO,
													 MeasuringChainPlatformInfo chainPlatformInfo,
													 PhysicalQuantityVO physicalQuantity,
													 Integer measuringTypeCode,Double yAxis){
		try {
			AbsoluteValueVO absoluteValueVO = parentPlatformVO.getAbsoluteValueVO();
			Double x;
			Double y;
			Double z;
			Double alpha;
			Double beta;
			Double gama;
			PhysicalQuantityVO physicalQuantityVO = parentPlatformVO.getPhysicalQuantityVO();//付侧台的物理量
			Boolean dir = Objects.equals(measuringTypeCode,1);//测量连方向

			AbsoluteDeflection parentDeflect = new AbsoluteDeflection();//父侧台工程量
			parentDeflect.setZ(absoluteValueVO.getZ());
			parentDeflect.setX(absoluteValueVO.getX());
			parentDeflect.setY(absoluteValueVO.getY());
			parentDeflect.setAlpha(absoluteValueVO.getAlpha());
			parentDeflect.setBeta(absoluteValueVO.getBeta());
			parentDeflect.setGama(absoluteValueVO.getGama());


			AbsoluteDeflection childDeflect = new AbsoluteDeflection();//本侧台的工程量
			childDeflect.setBeta(physicalQuantity.getDipY());


			RelativeDeflection relativeDeflect = new RelativeDeflection();//本侧台的物理量
			relativeDeflect.setNX(physicalQuantity.getNX());
			relativeDeflect.setNZ(physicalQuantity.getNZ());
			relativeDeflect.setZX(physicalQuantity.getZX());
			relativeDeflect.setZZ(physicalQuantity.getZZ());


			if(!dir){//如果是逆向的时候DeltaY取父级测台的DeltaY
				Double deltaY = physicalQuantityVO.getDeltaY();
				relativeDeflect.setDeltaY(deltaY);
			}else {
				relativeDeflect.setDeltaY(physicalQuantity.getDeltaY());
			}

			CalModel calModel = new CalModel();
			AbsoluteDeflection cal = calModel.cal(dir,
				parentDeflect,
				childDeflect,
				relativeDeflect,
				chainPlatformInfo.getyAxis(),
				chainPlatformInfo.getPreviousDistance(),
				chainPlatformInfo.getxAxis(),yAxis);



			x = cal.getX();
			//alpha = cal.getAlpha();
			alpha  = physicalQuantity.getDipX();
			y = cal.getY();
			z = cal.getZ();
			beta = physicalQuantity.getDipY();
			//beta = cal.getBeta();//倾角Y


			gama = cal.getGama();
			List<String> strings = new ArrayList<>();
			if(measuringPlatformConfigVO!=null){//走配置的策略

				Integer xType = measuringPlatformConfigVO.getxType();
				if(xType!=null){
					if(xType.equals(DataStrategyEnum.MANUAL.getCode())){
						x = Double.parseDouble(measuringPlatformConfigVO.getxValue());
					}else {
						//未给出结算规则
					}
				}
				Integer yType = measuringPlatformConfigVO.getyType();
				if(yType!=null){
					if(yType.equals(DataStrategyEnum.MANUAL.getCode())){
						y = Double.parseDouble(measuringPlatformConfigVO.getyValue());
					}else {
						//未给出结算规则
					}
				}
				Integer zType = measuringPlatformConfigVO.getzType();
				if(zType!=null){
					if(zType.equals(DataStrategyEnum.MANUAL.getCode())){
						z = Double.parseDouble(measuringPlatformConfigVO.getzValue());
					}else {
						//未给出结算规则
					}
				}
				Map<String, Double> dataStrategy;
				Integer alphaType = measuringPlatformConfigVO.getAlphaType();
				if(alphaType!=null){
					if(alphaType.equals(DataStrategyEnum.MANUAL.getCode())){
						alpha = Double.parseDouble(measuringPlatformConfigVO.getAlphaValue());
					}else if(alphaType.equals(DataStrategyEnum.COMPANY.getCode())){
						dataStrategy =  getDataStrategy(measuringPlatformConfigVO.getMeasuringPlatformId(),measuringPlatformConfigVO.getAlphaValue(),measuringPlatformConfigVO.getPlatformTypeCode(),deviceList);//ccd1AfterDipx1
						alpha = dataStrategy.get("dipX");

						strings.add(measuringPlatformConfigVO.getAlphaValue());
					}
				}
				Integer betaType = measuringPlatformConfigVO.getBetaType();
				if(betaType!=null){
					if(betaType.equals(DataStrategyEnum.MANUAL.getCode())){
						beta = Double.parseDouble(measuringPlatformConfigVO.getBetaValue());
					}else if(betaType.equals(DataStrategyEnum.COMPANY.getCode())){
						dataStrategy = getDataStrategy(measuringPlatformConfigVO.getMeasuringPlatformId(),measuringPlatformConfigVO.getBetaValue(), measuringPlatformConfigVO.getPlatformTypeCode(), deviceList);
						beta = dataStrategy.get("dipY");
						strings.add(measuringPlatformConfigVO.getBetaValue());
					}
				}
				Integer gamaType = measuringPlatformConfigVO.getGamaType();
				if(gamaType!=null){
					if(gamaType.equals(DataStrategyEnum.MANUAL.getCode())){
						gama = Double.parseDouble(measuringPlatformConfigVO.getGamaValue());
					}else if(gamaType.equals(DataStrategyEnum.COMPANY.getCode())){
						//没有提供算法
					}
				}
			}
			return AbsoluteValueVO.builder().x(x).y(y).z(z).alpha(alpha).beta(beta).gama(gama).stringList(strings).build();
		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;

	}
	/**
	 * 普通测台计算物理量
	 * @param deviceListDTO
	 * @param parentPlatformId
	 * @return
	 */
	private PhysicalQuantityVO getPhysicalQuantity(DeviceRuningStateDTO.DeviceListDTO deviceListDTO,
												   Long parentPlatformId,
												   Integer measuringTypeCode,
												   List<DeviceRuningStateDTO.DeviceListDTO> deviceList,Long id,String deviceId,Long deptMeasuringInfoId){

		try {
			List<SysParameter> sysParameterList = iSysParameterService.list(Wrappers.<SysParameter>query().lambda().eq(SysParameter::getMeasuringPlatformId,id));
			List<DeviceRuningStateDTO.DeviceListDTO.AttributeListDTO> attributeListDTO = deviceListDTO.getAttributeListDTO();
			MeasuringPlatformTypeVO parentPlatformTypeVO = iMeasuringPlatformTypeService.deileMeasuringPlatformType(parentPlatformId,measuringTypeCode);
			if(parentPlatformTypeVO!=null&&Objects.equals(parentPlatformTypeVO.getMeasuringPlatformType(), BenchTypeNameEnum.BASICS.getCode())){//付侧台位基点侧台

				AbsolutelyValueTable one = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
					.eq(AbsolutelyValueTable::getDeptId,deviceId)
					.eq(AbsolutelyValueTable::getMeasurChainDirection,measuringTypeCode));
				Integer ccd3_after_tangential_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_after_tangential_y")).findFirst().get().getValue();
				Integer ccd3_front_tangential_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_front_tangential_y")).findFirst().get().getValue();
				// Double deltaY = baseStationAlgorithm.getDeformation(ccd3_after_tangential_y,ccd3_front_tangential_y);
				Double deltaY = getModelData(Arrays.asList(ccd3_after_tangential_y, ccd3_front_tangential_y), sysParameterList, PhysicalQuantityEnum.DELTAY);

				Integer ccd1_after_dip_x = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_after_dip_y")).findFirst().get().getValue();
				Integer ccd1_front_dip_x = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_front_dip_y")).findFirst().get().getValue();
				//Double dipX = (ccd1_after_dip_x + ccd1_front_dip_x) / 2 * 0.0047 / 2000;
				Double dipX = getModelData(Arrays.asList(ccd1_after_dip_x, ccd1_front_dip_x), sysParameterList,PhysicalQuantityEnum.DIPX);


				Integer ccd2_after_dip_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_after_dip_x")).findFirst().get().getValue();
				Integer ccd2_front_dip_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_front_dip_x")).findFirst().get().getValue();
				//  Double dipY = (ccd2_after_dip_y+ ccd2_front_dip_y ) / 2 * 0.0047 / 2000;
				Double dipY = getModelData(Arrays.asList(ccd2_after_dip_y, ccd2_front_dip_y), sysParameterList,PhysicalQuantityEnum.DIPY);
				if(one==null){
					one = new AbsolutelyValueTable();
					one.setMeasurChainCode(deptMeasuringInfoId);
					one.setMeasurChainDirection(measuringTypeCode);
					one.setDeptId(deviceId);
					one.setzX(0.0);
					one.setnX(0.0);
					one.setzZ(0.0);
					one.setnZ(0.0);


					one.setDipY(dipY);
					one.setDipX(dipX);
					one.setDeltaY(deltaY);
					one.setInsertTime(System.currentTimeMillis());
					iAbsolutelyValueTableService.save(one);
				}
				dipY = dipY - one.getDipY();
				dipX = dipX - one.getDipX();
				deltaY = deltaY - one.getDeltaY();
				return PhysicalQuantityVO.builder().zX(0.0).nZ(0.0).zZ(0.0).zZ(0.0).nX(0.0).deltaY(deltaY).dipX(dipX).dipY(dipY).build();
			}else {
				AbsolutelyValueTable one = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
					.eq(AbsolutelyValueTable::getDeptId,deviceId)
					.eq(AbsolutelyValueTable::getMeasurChainDirection,measuringTypeCode));


				if(measuringTypeCode==1){//正向
					if(parentPlatformId==null){
						Double dipY = 0.0;
						Double deltaY = 0.0;
						Double dipX = 0.0;
						if(one==null){
							one = new AbsolutelyValueTable();
							one.setMeasurChainCode(deptMeasuringInfoId);
							one.setMeasurChainDirection(measuringTypeCode);
							one.setDeptId(deviceId);
							one.setzX(0.0);
							one.setnX(0.0);
							one.setzZ(0.0);
							one.setnZ(0.0);
							one.setDipY(0.0);
							one.setDipX(0.0);
							one.setDeltaY(0.0);
							one.setInsertTime(System.currentTimeMillis());
							iAbsolutelyValueTableService.save(one);
						}
						dipY = dipY - one.getDipY();
						dipX = dipX - one.getDipX();
						deltaY = deltaY - one.getDeltaY();
						return PhysicalQuantityVO.builder().zX(0.0).nZ(0.0).zZ(0.0).zZ(0.0).nX(0.0).deltaY(deltaY).dipX(dipX).dipY(dipY).build();
					}


					Integer ccd1_x_front_forward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_x_front_forward")).findFirst().get().getValue();
					Integer ccd1_x_after_forward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_x_after_forward")).findFirst().get().getValue();
					Integer ccd4_x_after_forward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd4_x_after_forward")).findFirst().get().getValue();
					Integer ccd4_x_front_forward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd4_x_front_forward")).findFirst().get().getValue();
					// Double zx = baseStationAlgorithm.getPhysicalQuantityFormula(ccd1_x_after_forward, ccd1_x_front_forward, ccd4_x_after_forward, ccd4_x_front_forward);
					log.info("zxccd值:{}",Arrays.asList(ccd1_x_after_forward, ccd1_x_front_forward,ccd4_x_after_forward,ccd4_x_front_forward));
					Double zx = getModelData(Arrays.asList(ccd1_x_after_forward, ccd1_x_front_forward,ccd4_x_after_forward,ccd4_x_front_forward), sysParameterList,PhysicalQuantityEnum.ZX);
					log.info("zxccd值:{}",Arrays.asList(ccd1_x_after_forward,ccd4_x_after_forward));
					Double zx2 = getModelData(Arrays.asList(ccd1_x_after_forward,ccd4_x_after_forward), sysParameterList,PhysicalQuantityEnum.ZX);
					log.info("zxccd值:{}",Arrays.asList(ccd1_x_front_forward,ccd4_x_front_forward));
					Double zx3 = getModelData(Arrays.asList( ccd1_x_front_forward,ccd4_x_front_forward), sysParameterList,PhysicalQuantityEnum.ZX);

					//单独计算前沿  和单独计算后延

					Integer ccd2_z_after_forward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_z_after_forward")).findFirst().get().getValue();
					Integer ccd2_z_front_forward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_z_front_forward")).findFirst().get().getValue();
					Integer ccd3_z_after_forward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_z_after_forward")).findFirst().get().getValue();
					Integer ccd3_z_front_forward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_z_front_forward")).findFirst().get().getValue();
					// Double zz = baseStationAlgorithm.getPhysicalQuantityFormula(ccd2_z_after_forward, ccd2_z_front_forward, ccd3_z_after_forward, ccd3_z_front_forward);
					Double zz = getModelData(Arrays.asList(ccd2_z_after_forward, ccd2_z_front_forward,ccd3_z_after_forward,ccd3_z_front_forward), sysParameterList,PhysicalQuantityEnum.ZZ);
					Double zz2 = getModelData(Arrays.asList(ccd2_z_after_forward,ccd3_z_after_forward), sysParameterList,PhysicalQuantityEnum.ZZ);
					Double zz3 = getModelData(Arrays.asList(ccd2_z_front_forward,ccd3_z_front_forward), sysParameterList,PhysicalQuantityEnum.ZZ);



					String deviceChannelId = parentPlatformTypeVO.getDeviceChannelId();
					List<DeviceRuningStateDTO.DeviceListDTO.AttributeListDTO> parentDTO = null;
					Optional<DeviceRuningStateDTO.DeviceListDTO> first = deviceList.stream().filter(l -> l.getDeviceId().equals(deviceChannelId)).findFirst();
					if(first.isPresent()){
						parentDTO = first.get().getAttributeListDTO();
					}else {
						//读取默认值
					}
					assert parentDTO != null;

					//List<MeasuringPlatformConfigVO> list = parentPlatformTypeVO.getList();
					//高精度传感器带入计算的


					Integer ccd1_x_after_backward = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_x_after_backward")).findFirst().get().getValue();
					Integer ccd1_x_front_backward = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_x_front_backward")).findFirst().get().getValue();
					Integer ccd4_x_after_backward = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd4_x_after_backward")).findFirst().get().getValue();
					Integer ccd4_x_front_backward = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd4_x_front_backward")).findFirst().get().getValue();

					List<SysParameter> parentSysParameterList = iSysParameterService.list(Wrappers.<SysParameter>query().lambda().eq(SysParameter::getMeasuringPlatformId, parentPlatformTypeVO.getId()));

					Double nx = getModelData(Arrays.asList(ccd1_x_after_backward, ccd1_x_front_backward,ccd4_x_after_backward,ccd4_x_front_backward), parentSysParameterList,PhysicalQuantityEnum.NX);
					Double nx2 = getModelData(Arrays.asList(ccd1_x_after_backward,ccd4_x_after_backward), parentSysParameterList,PhysicalQuantityEnum.NX);
					Double nx3 = getModelData(Arrays.asList( ccd1_x_front_backward,ccd4_x_front_backward), parentSysParameterList,PhysicalQuantityEnum.NX);

					//CCD2-Z脉冲后沿-后向位移
					Integer ccd2_z_after_backward = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_z_after_backward")).findFirst().get().getValue();
					//CCD2-Z脉冲前沿-后向位移
					Integer ccd2_z_front_backward = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_z_front_backward")).findFirst().get().getValue();
					//CCD3-Z脉冲后沿-后向位移
					Integer ccd3_z_after_backward = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_z_after_backward")).findFirst().get().getValue();
					//CCD3-Z脉冲前沿-后向位移
					Integer ccd3_z_front_backward = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_z_front_backward")).findFirst().get().getValue();

					Double nz = getModelData(Arrays.asList(ccd2_z_after_backward, ccd2_z_front_backward,ccd3_z_after_backward,ccd3_z_front_backward), parentSysParameterList,PhysicalQuantityEnum.NZ);
					Double nz2 = getModelData(Arrays.asList(ccd2_z_after_backward,ccd3_z_after_backward), parentSysParameterList,PhysicalQuantityEnum.NZ);
					Double nz3 = getModelData(Arrays.asList(ccd2_z_front_backward,ccd3_z_front_backward), parentSysParameterList,PhysicalQuantityEnum.NZ);


					Integer ccd3_after_tangential_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_after_tangential_y")).findFirst().get().getValue();
					Integer ccd3_front_tangential_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_front_tangential_y")).findFirst().get().getValue();

					Integer ccd2_after_dip_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_after_dip_y")).findFirst().get().getValue();
					Integer ccd2_front_dip_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_front_dip_y")).findFirst().get().getValue();

					Integer ccd1_after_dip_x = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_after_dip_x")).findFirst().get().getValue();
					Integer ccd1_front_dip_x = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_front_dip_x")).findFirst().get().getValue();

					if(one==null){
						one = new AbsolutelyValueTable();
						one.setMeasurChainCode(deptMeasuringInfoId);
						one.setMeasurChainDirection(measuringTypeCode);
						one.setDeptId(deviceId);
						one.setzX(zx);
						one.setzZ(zz);
						one.setnX(nx);
						one.setnZ(nz);

						one.setCcd2FrontDipY(ccd2_front_dip_y);
						one.setCcd2AfterDipY(ccd2_after_dip_y);

						one.setCcd1AfterDipX(ccd1_after_dip_x);
						one.setCcd1FrontDipX(ccd1_front_dip_x);

						one.setCcd3AfterTangentialY(ccd3_after_tangential_y);
						one.setCcd3FrontTangentialY(ccd3_front_tangential_y);

						one.setInsertTime(System.currentTimeMillis());
						iAbsolutelyValueTableService.save(one);
						return PhysicalQuantityVO.builder().nZ(0.0).zX(0.0).zZ(0.0).nX(0.0).deltaY(0.0).dipY(0.0).dipX(0.0).build();
					}

					zx = zx - one.getzX();
					zz = zz - one.getzZ();
					nx = nx - one.getnX();
					nz = nz - one.getnZ();

					List<Double> dobleMath1 = getDobleMath2(ccd3_front_tangential_y , ccd3_after_tangential_y ,one.getCcd3FrontTangentialY(),one.getCcd3AfterTangentialY());
					Double deltaY = getModelData2(dobleMath1.get(0), sysParameterList, PhysicalQuantityEnum.DELTAY)
						- getModelData2(dobleMath1.get(1), sysParameterList, PhysicalQuantityEnum.DELTAY);



					double dipX;
					if(ccd2_after_dip_y>7000||(ccd2_after_dip_y<=500&&ccd2_after_dip_y>0)&&(ccd2_front_dip_y<7000&&ccd2_front_dip_y>500)){//异常点
						dipX = getModelData2(Double.valueOf(ccd2_front_dip_y), sysParameterList, PhysicalQuantityEnum.DIPY)
							- getModelData2(Double.valueOf(one.getCcd2FrontDipY()), sysParameterList, PhysicalQuantityEnum.DIPY);
					}else if(ccd2_front_dip_y>7000||(ccd2_front_dip_y<=500&&ccd2_front_dip_y>0)&&(ccd2_after_dip_y<7000&&ccd2_after_dip_y>500)){
						dipX = getModelData2(Double.valueOf(ccd2_after_dip_y), sysParameterList, PhysicalQuantityEnum.DIPY)
							- getModelData2(Double.valueOf(one.getCcd2AfterDipY()), sysParameterList, PhysicalQuantityEnum.DIPY);
					}else {
						List<Double> dobleMath2 = getDobleMath2(ccd2_after_dip_y , ccd2_front_dip_y,one.getCcd2AfterDipY(),one.getCcd2FrontDipY());
						dipX = getModelData2(dobleMath2.get(0), sysParameterList, PhysicalQuantityEnum.DIPY)
							- getModelData2(dobleMath2.get(1), sysParameterList, PhysicalQuantityEnum.DIPY);
					}



					List<Double> dobleMath3 = getDobleMath2(ccd1_front_dip_x , ccd1_after_dip_x,one.getCcd1FrontDipX() ,one.getCcd1AfterDipX());
					Double dipY = getModelData2(dobleMath3.get(0), sysParameterList,PhysicalQuantityEnum.DIPX)
						- getModelData2(dobleMath3.get(1), sysParameterList, PhysicalQuantityEnum.DIPX);

					return PhysicalQuantityVO.builder().nZ(nz).zX(zx).zZ(zz).nX(nx).deltaY(deltaY).dipY(dipY).dipX(dipX).ccd2AfterDipY(ccd2_after_dip_y)
						.ccd2FrontDipY(ccd2_front_dip_y)
						.ccd1FrontDipX(ccd1_front_dip_x)
						.ccd1AfterDipX(ccd1_after_dip_x)
						.ccd3AfterTangentialY(ccd3_after_tangential_y)
						.ccd3FrontTangentialY(ccd3_front_tangential_y).build();
				}else {//逆向
					if(parentPlatformId==null){
						Integer ccd3_after_tangential_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_after_tangential_y")).findFirst().get().getValue();
						Integer ccd3_front_tangential_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_front_tangential_y")).findFirst().get().getValue();
						log.info("1逆向deltaY值:{}",Arrays.asList(ccd3_after_tangential_y, ccd3_front_tangential_y));
						Double dipX = 0.0;
						Double dipY = 0.0;
						if(one==null){
							one = new AbsolutelyValueTable();
							one.setMeasurChainDirection(measuringTypeCode);
							one.setDeptId(deviceId);
							one.setzX(0.0);
							one.setnX(0.0);
							one.setzZ(0.0);
							one.setnZ(0.0);
							one.setDipY(0.0);
							one.setMeasurChainCode(deptMeasuringInfoId);
							one.setDipX(0.0);

							one.setCcd3AfterTangentialY(ccd3_after_tangential_y);
							one.setCcd3FrontTangentialY(ccd3_front_tangential_y);

							one.setInsertTime(System.currentTimeMillis());
							iAbsolutelyValueTableService.save(one);
						}
						dipY = dipY - one.getDipY();
						dipX = dipX - one.getDipX();

						List<Double> dobleMath1 = getDobleMath2(ccd3_front_tangential_y , ccd3_after_tangential_y ,one.getCcd3FrontTangentialY(),one.getCcd3AfterTangentialY());
						Double deltaY = getModelData2(dobleMath1.get(0), sysParameterList, PhysicalQuantityEnum.DELTAY)
							- getModelData2(dobleMath1.get(1), sysParameterList, PhysicalQuantityEnum.DELTAY);

						return PhysicalQuantityVO.builder().zX(0.0).nZ(0.0).zZ(0.0).zZ(0.0).nX(0.0).deltaY(deltaY).dipX(dipX).dipY(dipY).build();
					}
					Integer ccd1_x_front_backward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_x_front_backward")).findFirst().get().getValue();
					Integer ccd1_x_after_backward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_x_after_backward")).findFirst().get().getValue();
					Integer ccd4_x_after_backward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd4_x_after_backward")).findFirst().get().getValue();
					Integer ccd4_x_front_backward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd4_x_front_backward")).findFirst().get().getValue();
					//Double zx = baseStationAlgorithm.getPhysicalQuantityFormula(ccd1_x_front_backward, ccd1_x_after_backward, ccd4_x_after_backward, ccd4_x_front_backward);
					log.info("1逆向ccd值:{}",Arrays.asList(ccd1_x_front_backward, ccd1_x_after_backward,ccd4_x_after_backward,ccd4_x_front_backward));
					Double zx = getModelData(Arrays.asList(ccd1_x_front_backward, ccd1_x_after_backward,ccd4_x_after_backward,ccd4_x_front_backward), sysParameterList,PhysicalQuantityEnum.ZX);
					log.info("2逆向ccd值:{}",Arrays.asList(ccd1_x_after_backward,ccd4_x_after_backward));
					Double zx2 = getModelData(Arrays.asList(ccd1_x_after_backward,ccd4_x_after_backward), sysParameterList,PhysicalQuantityEnum.ZX);

					log.info("3逆向ccd值:{}",Arrays.asList(ccd1_x_front_backward,ccd4_x_front_backward));
					Double zx3 = getModelData(Arrays.asList(ccd1_x_front_backward,ccd4_x_front_backward), sysParameterList,PhysicalQuantityEnum.ZX);

					Integer ccd2_z_after_backward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_z_after_backward")).findFirst().get().getValue();
					Integer ccd2_z_front_backward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_z_front_backward")).findFirst().get().getValue();
					Integer ccd3_z_after_backward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_z_after_backward")).findFirst().get().getValue();
					Integer ccd3_z_front_backward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_z_front_backward")).findFirst().get().getValue();
					// Double zz = baseStationAlgorithm.getPhysicalQuantityFormula(ccd2_z_after_backward, ccd2_z_front_backward, ccd3_z_after_backward, ccd3_z_front_backward);
					Double zz = getModelData(Arrays.asList(ccd2_z_after_backward, ccd2_z_front_backward,ccd3_z_after_backward,ccd3_z_front_backward), sysParameterList,PhysicalQuantityEnum.ZZ);;
					Double zz2 = getModelData(Arrays.asList(ccd2_z_after_backward,ccd3_z_after_backward), sysParameterList,PhysicalQuantityEnum.ZZ);
					Double zz3 = getModelData(Arrays.asList(ccd2_z_front_backward,ccd3_z_front_backward), sysParameterList,PhysicalQuantityEnum.ZZ);


					String deviceChannelId = parentPlatformTypeVO.getDeviceChannelId();
					List<DeviceRuningStateDTO.DeviceListDTO.AttributeListDTO> parentDTO = null;
					Optional<DeviceRuningStateDTO.DeviceListDTO> first = deviceList.stream().filter(l -> l.getDeviceId().equals(deviceChannelId)).findFirst();
					if(first.isPresent()){
						parentDTO = first.get().getAttributeListDTO();
					}else {
						//读取默认值
					}
					assert parentDTO != null;
					Integer ccd1_x_after_forward_p = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_x_after_forward")).findFirst().get().getValue();
					Integer ccd1_x_front_forward_p = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_x_front_forward")).findFirst().get().getValue();
					Integer ccd4_x_after_forward_p = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd4_x_after_forward")).findFirst().get().getValue();
					Integer ccd4_x_front_forward_p = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd4_x_front_forward")).findFirst().get().getValue();
					//Double nx = baseStationAlgorithm.getPhysicalQuantityFormula(ccd1_x_after_forward_p, ccd1_x_front_forward_p, ccd4_x_after_forward_p, ccd4_x_front_forward_p);
					List<SysParameter> parentSysParameterList = iSysParameterService.list(Wrappers.<SysParameter>query().lambda().eq(SysParameter::getMeasuringPlatformId, parentPlatformTypeVO.getId()));
					Double nx = getModelData(Arrays.asList(ccd1_x_after_forward_p,ccd1_x_front_forward_p,ccd4_x_after_forward_p,ccd4_x_front_forward_p), parentSysParameterList,PhysicalQuantityEnum.NX);;
					Double nx2 = getModelData(Arrays.asList(ccd1_x_after_forward_p,ccd4_x_after_forward_p), parentSysParameterList,PhysicalQuantityEnum.NX);;
					Double nx3 = getModelData(Arrays.asList(ccd1_x_front_forward_p,ccd4_x_front_forward_p), parentSysParameterList,PhysicalQuantityEnum.NX);;


					Integer ccd2_z_after_forward_p = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_z_after_forward")).findFirst().get().getValue();
					Integer ccd2_z_front_forward_p = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_z_front_forward")).findFirst().get().getValue();
					Integer ccd3_z_after_forward_p = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_z_after_forward")).findFirst().get().getValue();
					Integer ccd3_z_front_forward_p = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_z_front_forward")).findFirst().get().getValue();
					//Double nz = baseStationAlgorithm.getPhysicalQuantityFormula(ccd2_z_after_forward_p, ccd2_z_front_forward_p, ccd3_z_after_forward_p, ccd3_z_front_forward_p);
					Double nz = getModelData(Arrays.asList(ccd2_z_after_forward_p,ccd2_z_front_forward_p,ccd3_z_after_forward_p,ccd3_z_front_forward_p), parentSysParameterList,PhysicalQuantityEnum.NZ);;
					Double nz2 = getModelData(Arrays.asList(ccd2_z_after_forward_p,ccd3_z_after_forward_p), parentSysParameterList,PhysicalQuantityEnum.NZ);
					Double nz3 = getModelData(Arrays.asList(ccd2_z_front_forward_p,ccd3_z_front_forward_p), parentSysParameterList,PhysicalQuantityEnum.NZ);


					Integer ccd3_after_tangential_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_after_tangential_y")).findFirst().get().getValue();
					Integer ccd3_front_tangential_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_front_tangential_y")).findFirst().get().getValue();
					// Double deltaY = baseStationAlgorithm.getDeformation(ccd3_after_tangential_y,ccd3_front_tangential_y);

             /*   log.info("1逆向deltaY值:{}",Arrays.asList(ccd3_after_tangential_y, ccd3_front_tangential_y));
                Double deltaY = getModelData(Arrays.asList(ccd3_after_tangential_y,ccd3_front_tangential_y), sysParameterList,PhysicalQuantityEnum.DELTAY);
                log.info("2逆向deltaY值:{}",Arrays.asList(ccd3_after_tangential_y));
                Double deltaY2 = getModelData(Arrays.asList(ccd3_after_tangential_y), sysParameterList,PhysicalQuantityEnum.DELTAY);
                log.info("3逆向deltaY值:{}",Arrays.asList(ccd3_front_tangential_y));
                Double deltaY3 = getModelData(Arrays.asList(ccd3_front_tangential_y), sysParameterList,PhysicalQuantityEnum.DELTAY);*/



					Integer ccd2_after_dip_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_after_dip_y")).findFirst().get().getValue();
					Integer ccd2_front_dip_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_front_dip_y")).findFirst().get().getValue();
					// double dipX = (ccd2_after_dip_y + ccd2_front_dip_y) / 2 * 0.0047 / 2000;
					//Double dipX = getModelData(Arrays.asList(ccd2_after_dip_y,ccd2_front_dip_y), sysParameterList,PhysicalQuantityEnum.DIPY);
					//Double dipX2 = getModelData(Arrays.asList(ccd2_front_dip_y), sysParameterList,PhysicalQuantityEnum.DIPY);
					//Double dipX3 = getModelData(Arrays.asList(ccd2_after_dip_y), sysParameterList,PhysicalQuantityEnum.DIPY);


					Integer ccd1_after_dip_x = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_after_dip_x")).findFirst().get().getValue();
					Integer ccd1_front_dip_x = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_front_dip_x")).findFirst().get().getValue();
					//Double dipY = (ccd1_after_dip_x + ccd1_front_dip_x) / 2 * 0.0047 / 2000;
             /*   Double dipY = getModelData(Arrays.asList(ccd1_after_dip_x,ccd1_front_dip_x), sysParameterList,PhysicalQuantityEnum.DIPX);

                Double dipY2 = getModelData(Arrays.asList(ccd1_front_dip_x), sysParameterList,PhysicalQuantityEnum.DIPX);
                Double dipY3 = getModelData(Arrays.asList(ccd1_after_dip_x), sysParameterList,PhysicalQuantityEnum.DIPX);
*/
					if(one==null){
						one = new AbsolutelyValueTable();
						one.setMeasurChainCode(deptMeasuringInfoId);
						one.setMeasurChainDirection(measuringTypeCode);
						one.setDeptId(deviceId);
						one.setzX(zx);
						one.setnX(nx);
						one.setzZ(zz);
						one.setnZ(nz);
						one.setCcd2FrontDipY(ccd2_front_dip_y);
						one.setCcd2AfterDipY(ccd2_after_dip_y);

						one.setCcd1AfterDipX(ccd1_after_dip_x);
						one.setCcd1FrontDipX(ccd1_front_dip_x);

						one.setCcd3AfterTangentialY(ccd3_after_tangential_y);
						one.setCcd3FrontTangentialY(ccd3_front_tangential_y);
						one.setInsertTime(System.currentTimeMillis());
						iAbsolutelyValueTableService.save(one);
						return PhysicalQuantityVO.builder().nZ(0.0).zX(0.0).zZ(0.0).nX(0.0).deltaY(0.0).dipY(0.0).dipX(0.0).build();
					}

					zx = zx - one.getzX();
					zz = zz - one.getzZ();
					nx = nx - one.getnX();
					nz = nz - one.getnZ();

					List<Double> dobleMath1 = getDobleMath2(ccd3_front_tangential_y , ccd3_after_tangential_y ,one.getCcd3FrontTangentialY(),one.getCcd3AfterTangentialY());
					Double deltaY = getModelData2(dobleMath1.get(0), sysParameterList, PhysicalQuantityEnum.DELTAY)
						- getModelData2(dobleMath1.get(1), sysParameterList, PhysicalQuantityEnum.DELTAY);



					double dipX;
					if(ccd2_after_dip_y>7000||(ccd2_after_dip_y<=500&&ccd2_after_dip_y>0)&&(ccd2_front_dip_y<7000&&ccd2_front_dip_y>500)){//异常点
						dipX = getModelData2(Double.valueOf(ccd2_front_dip_y), sysParameterList, PhysicalQuantityEnum.DIPY)
							- getModelData2(Double.valueOf(one.getCcd2FrontDipY()), sysParameterList, PhysicalQuantityEnum.DIPY);
					}else if(ccd2_front_dip_y>7000||(ccd2_front_dip_y<=500&&ccd2_front_dip_y>0)&&(ccd2_after_dip_y<7000&&ccd2_after_dip_y>500)){
						dipX = getModelData2(Double.valueOf(ccd2_after_dip_y), sysParameterList, PhysicalQuantityEnum.DIPY)
							- getModelData2(Double.valueOf(one.getCcd2AfterDipY()), sysParameterList, PhysicalQuantityEnum.DIPY);
					}else {
						List<Double> dobleMath2 = getDobleMath2(ccd2_after_dip_y , ccd2_front_dip_y,one.getCcd2AfterDipY(),one.getCcd2FrontDipY());
						dipX = getModelData2(dobleMath2.get(0), sysParameterList, PhysicalQuantityEnum.DIPY)
							- getModelData2(dobleMath2.get(1), sysParameterList, PhysicalQuantityEnum.DIPY);
					}



					List<Double> dobleMath3 = getDobleMath2(ccd1_front_dip_x , ccd1_after_dip_x,one.getCcd1FrontDipX() ,one.getCcd1AfterDipX());
					Double dipY = getModelData2(dobleMath3.get(0), sysParameterList,PhysicalQuantityEnum.DIPX)
						- getModelData2(dobleMath3.get(1), sysParameterList, PhysicalQuantityEnum.DIPX);


					return PhysicalQuantityVO.builder().nZ(nz).zX(zx).zZ(zz).nX(nx).deltaY(deltaY).dipY(dipY).dipX(dipX).ccd2AfterDipY(ccd2_after_dip_y)
						.ccd2FrontDipY(ccd2_front_dip_y)
						.ccd1FrontDipX(ccd1_front_dip_x)
						.ccd1AfterDipX(ccd1_after_dip_x)
						.ccd3AfterTangentialY(ccd3_after_tangential_y)
						.ccd3FrontTangentialY(ccd3_front_tangential_y).build();
				}
			}

		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;

	}
	/**
	 * 基点测台计算工程量
	 * @param measuringPlatformConfigVO
	 * @param deviceList
	 * @return
	 */
	private AbsoluteValueVO getAbsoluteValue( List<String> lists,
											  Map<String,DeviceTableVO> mapd ,
											  MeasuringPlatformConfigVO measuringPlatformConfigVO,
											  List<DeviceRuningStateDTO.DeviceListDTO> deviceList,
											  Long id,
											  Long acquisitionTime){
		try {
			double x = 0.0;
			double y = 0.0;
			Double z = null;
			Double alpha = null;
			Double beta = null;
			Double gama = null;

			List<DeviceRuningStateDTO.DeviceListDTO> collect = deviceList.stream().filter(l -> lists.contains(l.getDeviceId())).collect(Collectors.toList());
			List<SysParameter> sysParameterList = iSysParameterService.list(Wrappers.<SysParameter>query().lambda().eq(SysParameter::getMeasuringPlatformId,id));
			for (DeviceRuningStateDTO.DeviceListDTO deviceListDTO : collect) {
				// DeviceTable deviceTableVO = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda().eq(DeviceTable::getDeviceChannelId, deviceListDTO.getDeviceId()).eq(DeviceTable::getIsDeleted, 0));
				DeviceTableVO deviceTableVO = mapd.get(deviceListDTO.getDeviceId());

				List<DeviceRuningStateDTO.DeviceListDTO.AttributeListDTO> attributeListDTO = deviceListDTO.getAttributeListDTO();
				switch (Objects.requireNonNull(ProductTypeEnum.getEnum(deviceTableVO.getProductId()))){
					case HT_GONIOMETER://华腾绕角仪
						Integer ccd3_z_front = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd3_z_front")).findFirst().get().getValue();
						Integer ccd3_z_after = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd3_z_after")).findFirst().get().getValue();
						gama = getModelData(Arrays.asList(ccd3_z_front, ccd3_z_after), sysParameterList,PhysicalQuantityEnum.GAMA);
						//gama = baseStationAlgorithm.getPhysicalQuantityDip(Double.valueOf(rich_z_K), ccd3_z_after, ccd3_z_front, Double.valueOf(rich_z_B));
						//绕Z轴的旋转角
						break;
					case HT_DOUBLE_MARKER://华腾双标仪
						Integer ccd3_z_front1 = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd3_z_front")).findFirst().get().getValue();
						Integer ccd3_z_after1 = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd3_z_after")).findFirst().get().getValue();
						// z  = baseStationAlgorithm.getDeformation(ccd3_z_after1,ccd3_z_front1);
						z = getModelData(Arrays.asList(ccd3_z_front1, ccd3_z_after1), sysParameterList,PhysicalQuantityEnum.Z);
						break;
					case HT_PERPENDICULOMETER://华腾垂线仪
						Integer ccd3_x_front = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd3_x_front")).findFirst().get().getValue();
						Integer ccd3_x_after = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd3_x_after")).findFirst().get().getValue();
						alpha = getModelData(Arrays.asList(ccd3_x_front, ccd3_x_after), sysParameterList,PhysicalQuantityEnum.ALPHA);
						//alpha  = baseStationAlgorithm.getPhysicalQuantityDip(Double.valueOf(rich_x_K), ccd3_x_after, ccd3_x_front, Double.valueOf(rich_x_B));

						Integer ccd1_y_front = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd1_y_front")).findFirst().get().getValue();
						Integer ccd1_y_after = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd1_y_after")).findFirst().get().getValue();
						beta = getModelData(Arrays.asList(ccd1_y_front, ccd1_y_after), sysParameterList,PhysicalQuantityEnum.BETA);
						//beta  = baseStationAlgorithm.getPhysicalQuantityDip(Double.valueOf(rich_y_K), ccd1_y_after, ccd1_y_front, Double.valueOf(rich_y_B));
						break;
				}
			}
			List<String> strings = new ArrayList<>();
			if(measuringPlatformConfigVO!=null){//走配置的策略

				Integer xType = measuringPlatformConfigVO.getxType();
				if(xType!=null){
					if(xType.equals(DataStrategyEnum.MANUAL.getCode())){
						x = Double.parseDouble(measuringPlatformConfigVO.getxValue());
					}else {
						//未给出结算规则
					}

				}
				Integer yType = measuringPlatformConfigVO.getyType();
				if(yType!=null){
					if(yType.equals(DataStrategyEnum.MANUAL.getCode())){
						y = Double.parseDouble(measuringPlatformConfigVO.getyValue());
					}else {
						//未给出结算规则
					}
				}
				Integer zType = measuringPlatformConfigVO.getzType();
				if(zType!=null){
					if(zType.equals(DataStrategyEnum.MANUAL.getCode())){
						z = Double.parseDouble(measuringPlatformConfigVO.getzValue());
					}else {
						//未给出结算规则
					}
				}
				Map<String, Double> dataStrategy;
				Integer alphaType = measuringPlatformConfigVO.getAlphaType();
				if(alphaType!=null){
					if(alphaType.equals(DataStrategyEnum.MANUAL.getCode())){
						alpha = Double.parseDouble(measuringPlatformConfigVO.getAlphaValue());
					}else if(alphaType.equals(DataStrategyEnum.COMPANY.getCode())){
						dataStrategy =  getDataStrategy(id,measuringPlatformConfigVO.getAlphaValue(),measuringPlatformConfigVO.getPlatformTypeCode(),deviceList);//ccd1AfterDipx1
						alpha = dataStrategy.get("dipX");
						strings.add(measuringPlatformConfigVO.getAlphaValue());
					}
				}
				Integer betaType = measuringPlatformConfigVO.getBetaType();
				if(betaType!=null){
					if(betaType.equals(DataStrategyEnum.MANUAL.getCode())){
						beta = Double.parseDouble(measuringPlatformConfigVO.getBetaValue());
					}else if(betaType.equals(DataStrategyEnum.COMPANY.getCode())){
						dataStrategy = getDataStrategy(id,measuringPlatformConfigVO.getBetaValue(), measuringPlatformConfigVO.getPlatformTypeCode(), deviceList);
						beta = dataStrategy.get("dipY");
						strings.add(measuringPlatformConfigVO.getBetaValue());
					}
				}
				Integer gamaType = measuringPlatformConfigVO.getGamaType();
				if(gamaType!=null){
					if(gamaType.equals(DataStrategyEnum.MANUAL.getCode())){
						gama = Double.parseDouble(measuringPlatformConfigVO.getGamaValue());
					}else if(gamaType.equals(DataStrategyEnum.COMPANY.getCode())){
						//没有提供算法
					}
				}
			}

			return AbsoluteValueVO.builder().x(x).y(y).z(z).alpha(alpha).beta(beta).gama(gama).stringList(strings).build();
		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;

	}

	private Map<String,Double> getDataStrategy(Long measuringPlatformId,String value, Integer platformTypeCode, List<DeviceRuningStateDTO.DeviceListDTO> deviceList){

		try {
			Map<String,Double> map = new HashMap<>();
			List<DeviceRuningStateDTO.DeviceListDTO.AttributeListDTO> attributeListDTO;
			DeviceTable deviceTableVO = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda().eq(DeviceTable::getDeviceId,value).eq(DeviceTable::getIsDeleted, 0));
			Optional<DeviceRuningStateDTO.DeviceListDTO> first = deviceList.stream().filter(x -> x.getDeviceId().equals( deviceTableVO.getDeviceChannelId())).findFirst();
			if(first.isPresent()){
				DeviceRuningStateDTO.DeviceListDTO deviceListDTO = first.get();
				attributeListDTO = deviceListDTO.getAttributeListDTO();
			}else {
				//查询默认值
				attributeListDTO = new ArrayList<>();
			}
			//高精度传感器一次量


			Integer ccd2_after_dip_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_after_dip_y")).findFirst().get().getValue();
			Integer ccd2_front_dip_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_front_dip_y")).findFirst().get().getValue();

			Integer ccd1_after_dip_x = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_after_dip_x")).findFirst().get().getValue();
			Integer ccd1_front_dip_x = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_front_dip_x")).findFirst().get().getValue();


			AbsolutelyValueTable one = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
				.eq(AbsolutelyValueTable::getDeptId,value).eq(AbsolutelyValueTable::getMeasurChainDirection,platformTypeCode));

			List<SysParameter> sysParameterList = iSysParameterService.list(Wrappers.<SysParameter>query().lambda().eq(SysParameter::getMeasuringPlatformId,measuringPlatformId));
			if(one==null){
/*			Double v3 =  getModelData(Arrays.asList(ccd2_after_dip_y,ccd2_front_dip_y),sysParameterList,PhysicalQuantityEnum.DIPY);
			Double v2 =  getModelData(Arrays.asList(ccd1_after_dip_x,ccd1_front_dip_x),sysParameterList,PhysicalQuantityEnum.DIPX);*/
				one = new AbsolutelyValueTable();
				one.setMeasurChainDirection(platformTypeCode);
				one.setDeptId(value);
				one.setCcd2FrontDipY(ccd2_front_dip_y);
				one.setCcd2AfterDipY(ccd2_after_dip_y);

				one.setCcd1AfterDipX(ccd1_after_dip_x);
				one.setCcd1FrontDipX(ccd1_front_dip_x);
   /*         one.setDipX(v3);
            one.setDipY(v2);*/
				iAbsolutelyValueTableService.save(one);

				map.put("dipX",0.0);
				map.put("dipY",0.0);
				return map;
			}else {
				List<Double> dobleMath2 = getDobleMath2(ccd2_after_dip_y , ccd2_front_dip_y,one.getCcd2AfterDipY(),one.getCcd2FrontDipY());
				Double v1 = getModelData2(dobleMath2.get(0), sysParameterList, PhysicalQuantityEnum.DIPY)
					- getModelData2(dobleMath2.get(1), sysParameterList, PhysicalQuantityEnum.DIPY);



				List<Double> dobleMath3 = getDobleMath2(ccd1_front_dip_x , ccd1_after_dip_x,one.getCcd1FrontDipX() ,one.getCcd1AfterDipX());
				Double v = getModelData2(dobleMath3.get(0), sysParameterList,PhysicalQuantityEnum.DIPX)
					- getModelData2(dobleMath3.get(1), sysParameterList, PhysicalQuantityEnum.DIPX);

/*            Double v =  getModelData(Arrays.asList(ccd1_after_dip_x ,ccd1_front_dip_x ),sysParameterList,PhysicalQuantityEnum.DIPX);
            Double v1 =  getModelData(Arrays.asList(ccd2_after_dip_y ,ccd2_front_dip_y ),sysParameterList,PhysicalQuantityEnum.DIPY);*/
				map.put("dipX",v1);
				map.put("dipY",v);
				log.info("高精度传感器计算map:{}",map);
				return map;
			}

		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;




	}
	private Double saveMeasuringChainDetails(List<MeasuringChainDetailsVO> measuringChainDetailsVOs,String acquisitionFlag,Integer arcsecondType,Double arcsecondValue,Integer measurChainDirection) {
		try {
			MeasuringChainDetailsVO zhengx = measuringChainDetailsVOs.stream().filter(x -> x.getMeasurChainDirection() == measurChainDirection).findFirst().orElse(null);//正向
			MeasuringPlatformVO x1 = zhengx.getMeasuringPlatformVOS().stream().filter(l1 -> l1.getMeasuringPlatformId() == 1701072301627441154L).findFirst().get();
			return x1.getAbsoluteValueVO().getX();

		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;

	}

	private Double getModelData(List<Integer> x, List<SysParameter> sysParameterList,PhysicalQuantityEnum physicalQuantityEnum){
		try {
			log.info("标定系数physicalQuantityEnum:{}",physicalQuantityEnum);
			log.info("CCD值:{}",x);
			log.info("标定系数sysParameterList:{}",sysParameterList);

			Double collect = x.stream().collect(Collectors.averagingDouble(item -> item));
			SysParameter first = sysParameterList.stream().filter(l ->
				l.getParameterKey().equals(physicalQuantityEnum.getCode())
					&& l.getMinValue() <= collect
					&& l.getMaxValue() > collect).findFirst().get();
			double v = first.getDipXK() * collect + first.getDipXB();
			BigDecimal bigDecimal = new BigDecimal(v).setScale(14, RoundingMode.DOWN);
			return bigDecimal.doubleValue();
		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;

	}

	private Double getModelData2(Double x, List<SysParameter> sysParameterList,PhysicalQuantityEnum physicalQuantityEnum){
		try {
			log.info("标定系数physicalQuantityEnum:{}",physicalQuantityEnum);
			log.info("CCD值:{}",x);
			log.info("标定系数sysParameterList:{}",sysParameterList);
			SysParameter first = sysParameterList.stream().filter(l ->
				l.getParameterKey().equals(physicalQuantityEnum.getCode())
					&& l.getMinValue() <= x
					&& l.getMaxValue() > x).findFirst().get();
			double v = first.getDipXK() * x + first.getDipXB();
			BigDecimal bigDecimal = new BigDecimal(v).setScale(14, RoundingMode.DOWN);
			return bigDecimal.doubleValue();
		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;

	}



	public List<Double> getDobleMath2(Integer x1,Integer x2,Integer x3,Integer x4){
		try {
			Double abs = (double) Math.abs(x1 - x3);
			Double abs1 = (double) Math.abs(x2 - x4);
			Double collect1 = Stream.of(x1, x2).collect(Collectors.averagingDouble(item -> item));
			Double collect2 = Stream.of(x3, x4).collect(Collectors.averagingDouble(item -> item));
			Double collect = Math.abs(collect1 - collect2);
			Double min = Collections.min( Arrays.asList(abs, abs1,collect));
			if(abs.equals(min)){
				return Arrays.asList((double) x1,(double) x3);
			}else  if(abs1.equals(min)){
				return Arrays.asList((double) x2,(double) x4);
			}else {
				return Arrays.asList(collect1,collect2);
			}
		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;

	}
	public Double getDobleMath(Double x1,Double x2,Double x3){
		try {
			Double min = Collections.min(Arrays.asList(Math.abs(x1), Math.abs(x2), Math.abs(x3)));
			if(Math.abs(x1)==min){
				return x1;
			}else if(Math.abs(x2)==min){
				return x2;
			}else {
				return x3;
			}

		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;

	}

}
